<template>
  <div class="personal">
    <!-- 上半部 -->
    <div class="personal-top">
      <img :src="avatarUrl" alt="" class="personal-img" />
      <div>
        <div>
          <span class="personal-name">{{ nickname }}</span>
          <div class="personal-top-content">
            <div>
              <button class="personal-Lv">
                LV<span>{{ level }}</span>
              </button>
              <i class="el-icon-male personal-i"></i>
            </div>
            <div>
              <el-button
                round
                icon="el-icon-edit"
                v-if="isBtn"
                @click="gobianjiPage"
                >编辑个人信息</el-button
              >
              <el-button round icon="el-icon-edit" v-else>关注</el-button>
            </div>
          </div>
        </div>
        <div class="personal-top-bootom">
          <div class="personal-top-bootom-a">
            <div>
              <a href="#" class="personal-top-bootom-a-Item01">{{
                eventCount
              }}</a>
            </div>
            <div><a href="#" class="personal-top-bootom-a-Item02">动态</a></div>
          </div>
          <div class="personal-top-bootom-a">
            <div>
              <router-link
                :to="`/userfans/${userId}/1`"
                class="personal-top-bootom-a-Item01"
                >{{ follows }}</router-link
              >
            </div>
            <div>
              <router-link
                :to="`/userfans/${userId}/1`"
                class="personal-top-bootom-a-Item02"
                >关注</router-link
              >
            </div>
          </div>
          <div class="personal-top-bootom-a aEnd">
            <div>
              <router-link
                :to="`/userfans/${userId}/0`"
                class="personal-top-bootom-a-Item01"
                >{{ followeds }}</router-link
              >
            </div>
            <div>
              <router-link
                :to="`/userfans/${userId}/0`"
                class="personal-top-bootom-a-Item02"
                >粉丝</router-link
              >
            </div>
          </div>
        </div>
        <div class="personal-top-bootom-label">
          <span>所在地区:</span><span>江西省 鹰潭市</span>
        </div>
        <div class="personal-top-bootom-label">
          <span>社交网络:</span
          ><i
            class="
              login-btnCircle
              iconfont
              icon-weibo
              personal-top-bootom-iconI
            "
          ></i>
        </div>
        <div class="personal-top-bootom-label">
          <span>个人介绍:</span><span>{{ signature }}</span>
        </div>
      </div>
    </div>
    <div class="personal-bootom">
      <div class="personal-bootom-title">我创建的歌单</div>
      <div class="personal-bootom-allImg">
        <div class="item">
          <router-link to="#">
            <img
              src="../../static/images/music01.jpg"
              alt=""
              class="personal-bootom-img"
            />
          </router-link>
          <div class="personal-bootom-span"><span>我的听歌排行</span></div>
          <div class="personal-bootom-text">累计听歌<span>270</span>首</div>
        </div>
        <!-- 渲染歌单信息 -->
        <div v-for="(item, index) in playlist" :key="index" class="item">
          <router-link
            :to="{
              name: 'Songsheet',
              query: {
                id: item.id,
              },
            }"
          >
            <img :src="item.coverImgUrl" alt="" class="personal-bootom-img" />
          </router-link>
          <div class="personal-bootom-span">
            <span>{{ item.name }}</span>
          </div>
          <div class="personal-bootom-text">
            <span>{{ item.trackCount }}</span
            >首
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations } from "vuex";

// 个人中心页面
export default {
  name: "Personal",
  data() {
    return {
      nickname: "", //用户的名称
      level: "", //用户等级
      avatarUrl: "", //头像照片
      userId: 0, //当前页面用户的id
      signature: "", //用户的个人介绍
      follows: 0, //关注的人数
      gender: 1, //性别
      eventCount: 0, //动态个数
      followeds: 0, //粉丝个数
      playlist: [], //获取歌单信息
    };
  },
  methods: {
    ...mapMutations("home", ["UPDATEDIALOGVISIBLE"]),
    //获取用户详细信息
    async getUserDetail() {
      let profile = localStorage.getItem("profile");
      if (this.$route.params.id) {
        this.userId = this.$route.params.id;
      } else if (profile) {
        this.userId = JSON.parse(profile).userId; //通过JSON解析为对象
      } else {
        //展示登录页
        this.UPDATEDIALOGVISIBLE(true);
      }
      let res = await this.$API.personal.getUserDetail(this.userId);
      console.log(res);
      //收集数据渲染页面
      this.nickname = res.profile.nickname;
      this.level = res.level;
      this.avatarUrl = res.profile.avatarUrl;

      this.signature = res.profile.signature;
      this.follows = res.profile.follows;
      this.gender = res.profile.gender;
      this.eventCount = res.profile.eventCount;
      this.followeds = res.profile.followeds;
    },
    //获取歌单
    async getGedan() {
      let { userId } = this;
      let res = await this.$API.personal.getGedan(userId);
      this.playlist = res.playlist;
      console.log("sssss", this.playlist);
    },
    //点击编辑个人信息，去往编辑页面
    gobianjiPage() {
      this.$router.history.push("/personalmessage");
    },
  },
  mounted() {
    this.getUserDetail();
    this.getGedan();
    // let id=this.$route.params.id
    // if(id){
    //    this.getUserDetail();
    // }

    // this.getUserMessage();
  },
  computed: {
    isBtn() {
      return this.userId == JSON.parse(localStorage.getItem("profile")).userId;
    },
  },
};
</script>

<style scoped>
.personal {
  width: 1020px;
  border-bottom: 1px solid #e0e0e0;
  padding-bottom: 50px;
}
.personal-top {
  display: flex;
  margin-left: 20px;
  margin-top: 10px;
}
.personal-top-content {
  width: 730px;
  display: flex;
  padding-bottom: 5px;
  border-bottom: 1px solid #e5e5e5;
  justify-content: space-between;
}
.personal-name {
  font-size: 30px;
  font-weight: bold;
}
.personal-img {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  margin-right: 40px;
}
.personal-Lv {
  border-radius: 45%;
  border: none;
  margin-right: 10px;
}
.personal-i {
  background: #c0f3ff;
  border-radius: 50%;
  color: #69bde1;
}
.personal-top-bootom {
  margin-top: 15px;
  display: flex;
}
.personal-top-bootom-a {
  width: 50px;
  height: 50px;
  /* border: 1px solid red; */
  text-align: center;
  padding: 0 10px;
  border-right: 1px solid #e6e6e6;
}
.personal-top-bootom-a-Item01 {
  text-decoration: none;
  color: #373737;
}
.personal-top-bootom-a-Item02 {
  text-decoration: none;
  color: #676767;
  font-size: 12px;
}
.aEnd {
  border-right: none;
}
/* 下半部分 */
.personal-top-bootom-label {
  font-size: 12px;
  padding-left: 20px;
  padding-bottom: 5px;
}
.personal-top-bootom-iconI {
  padding-left: 10px;
}
.personal-bootom {
  margin-left: 20px;
  margin-top: 30px;
}
.personal-bootom-title {
  font-weight: bold;
}
.personal-bootom-allImg {
  display: flex;
  flex-wrap: wrap;
}
.personal-bootom-allImg > .item {
  width: 200px;
  margin-right: 50px;
}
.personal-bootom-img {
  width: 200px;
  height: 200px;
  margin-top: 20px;
  margin-right: 50px;
  border-radius: 10px;
}
.personal-bootom-span {
  margin-top: 10px;
}
.personal-bootom-text {
  margin-top: 10px;
  font-size: 12px;
  color: #9f9f9f;
}
</style>